/*
 * SqlDerbyDAOFactory.java
 *
 * Created on 21. kv�ten 2007, 23:08
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */
package dao.sql;

import dao.AbstractDAOFactory;
import dao.ApplicationSettingsDAO;
import dao.FolderDAO;
import dao.ImageEntryDAO;
import scriptella.execution.EtlExecutor;
import scriptella.execution.EtlExecutorException;

import java.sql.Connection;
import java.sql.DriverManager;

public class HsqldbDAOFactory extends AbstractDAOFactory {

    Connection connection;
    static final String URL = "jdbc:hsqldb:file:testdb";
    static final String USER = "admin";
    static final String PASSWORD = "adminadmin";

    public HsqldbDAOFactory() throws Exception {
        this(URL, null, null);
    }

    public HsqldbDAOFactory(String url, String user, String password) throws Exception {
        try {
            Class.forName("org.hsqldb.jdbcDriver");
        } catch (ClassNotFoundException ex) {
            ex.printStackTrace();
        }
        connection = DriverManager.getConnection(URL, user, password);
        try {
            EtlExecutor.newExecutor(getClass().getResource("scriptella.xml")).execute(); //Execute etl.xml file loaded from classpath
        } catch (EtlExecutorException e) {
            e.printStackTrace();
        }

    }

    @Override
    public ImageEntryDAO getImageEntryDAO() throws Exception {
        return null;
    }

    public FolderDAO getFolderDAO() throws Exception {
        return new HsqldbFolderDAO(connection);
    }

    @Override
    public ApplicationSettingsDAO getApplicationSettingsDAO() throws Exception {
        return null;
    }

//    public ReaderDAOInterface getReadersDAO() throws ShopException {
//        return new SqlDerbyReadersDAO(connection);
//    }
//
//    public BorrowsDAOInterface getBorrowsDAO() throws ShopException {
//        return new SqlDerbyBorrowsDAO(connection);
//    }

    public void close() throws Exception {
        connection.close();

    }
}